//
//  NSString+AutoHeight.m
//  League of Legends
//
//  Created by qianfeng0 on 16/5/15.
//  Copyright © 2016年 qianfeng0. All rights reserved.
//

#import "NSString+AutoHeight.h"

@implementation NSString (AutoHeight)

/*计算文本的size*/
- (CGSize)ch_sizeWithFont:(UIFont *)font size:(CGSize)size {
    NSDictionary *dict = @{NSFontAttributeName:font};
    CGRect rect = [self boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    return rect.size;
}
/* 根据文本的宽度计算文本的高度*/
- (CGFloat)ch_heightWithFont:(UIFont *)font width:(CGFloat)width {
    CGSize size = [self ch_sizeWithFont:font size:CGSizeMake(width, MAXFLOAT)];
    return size.height;
}

@end
